//
// Created by subject on 2025/2/25.
//

#ifndef DEEPSEEKTEST_JAVASIMPLEMANAGER_H
#define DEEPSEEKTEST_JAVASIMPLEMANAGER_H

#include <jni.h>
#include "LogUtils.h"
#include "rkllm.h"
#include "iostream"
#include <mutex>

class JavaSimpleManager{

private:
    //    查找函数：查找类
    static jclass findClass(JNIEnv* env, const char* className);
//    通用函数：获取方法ID
    static jmethodID getMethodID(JNIEnv* env, jclass clazz, const char* methodName, const char* methodSig);
//    通用函数：获取静态方法ID
    static jmethodID getStaticMethodID(JNIEnv* env, jclass clazz, const char* methodName, const char* methodSig);

    // 通用函数：清理全局引用
    template <typename T>
    static void safeDeleteGlobalRef(JNIEnv* env, T& globalRef) {
        if (globalRef != nullptr) {
            env->DeleteLocalRef(globalRef);
            globalRef = nullptr;
        }
    }

public:
    static bool initJavaSimple(JNIEnv *env);
    static void destoryJaveSimple(JNIEnv *env);
    static bool callJavaSimple(JNIEnv *env, const char *text, const int state);
    static bool callJavaFinish(JNIEnv *env);

};


#endif //DEEPSEEKTEST_JAVASIMPLEMANAGER_H
